package charley.wu.executor.test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.LockSupport;

/**
 * 功能描述
 *
 * @author Charley
 * @since 1.0
 */
public class ThreadTask implements Runnable {

  private final long start;
  private AtomicLong cost;
  private final CountDownLatch completeLatch;

  public ThreadTask(AtomicLong cost, CountDownLatch completeLatch) {
    this.cost = cost;
    this.completeLatch = completeLatch;
    start = System.nanoTime();
  }

  /**
   * When an object implementing interface <code>Runnable</code> is used
   * to create a thread, starting the thread causes the object's
   * <code>run</code> method to be called in that separately executing
   * thread.
   * <p>
   * The general contract of the method <code>run</code> is that it may
   * take any action whatsoever.
   *
   * @see Thread#run()
   */
  @Override
  public void run() {
    LockSupport.parkNanos(1*1000*1000);
//    cost.addAndGet((System.nanoTime() - start)/1000);
    completeLatch.countDown();
  }
}
